const {Logger} = require('./log');
class BusinessError extends Error {
  constructor({message, statusCode}) {
    super();
    this.statusCode = statusCode;
    this.message = message;
  }
}

const handleError = (err, req,res,next) => {
  let {statusCode, message} = err;
  Logger.error(message);
  if (!statusCode){
      statusCode = 500;
  }
  res.status(statusCode).json({
    status: 'error',
    statusCode,
    message,
  });
};
module.exports = {
    handleError,
    BusinessError
}